sequenceDiagram

  participant Client as RetrievalClient
  participant Node
  participant Provider as RetrievalProvider
  participant BSC as BlockStore (Client)
  participant BSP as BlockStore (Provider)
  participant StorageMiner as Storage Miner Subsystem

  opt Discovery
    Client ->> Node : Query Chain For Providers w/ PieceID
    activate Node
    Node -->> Client : Providers With PieceID
    deactivate Node
  end

  Client ->> Provider : Send Query for Piece
  activate Provider
  Provider -->> Client : Send information about Piece (price, size, etc)
  deactivate Provider
  Client ->> Provider : Send RetrievalDealProposal
  activate Provider
  Provider -->> Client : Send RetrievalDealResponse, accepting
  opt Create Payment Channel
  activate Client
  Client ->> Node : Create Payment Channel
  activate Node
  Node -->> Client : Message For Channel Gets On Chain
  deactivate Client
  deactivate Node
  end
  opt Unsealing
  Provider ->> StorageMiner : Unseal Sector
  activate StorageMiner
  StorageMiner -->> Provider : Unsealed Piece Data
  deactivate StorageMiner
  Provider ->> BSP: Write Piece Blocks to BlockStore
  activate BSP
  BSP -->> Provider : Blocks written
  deactivate BSP
  end
  loop Retrieve In Pieces
    loop Sending Data until Payment Required
        Provider ->> BSP: Read Blocks from BlockStore
        activate BSP
        BSP -->> Provider : Blocks
        deactivate BSP
        Provider ->> Client : Send Blocks
        activate Client
        Client ->> Client : Verify Blocks
        Client ->> BSC : Write Blocks
        activate BSC
        BSC --> Client: Blocks written
        deactivate BSC
        deactivate Client
    end
    Provider ->> Client : Request Payment
    activate Client
    Client ->> Node : Create Voucher On Payment Channel
    activate Node
    Node -->> Client : Message For Voucher Gets On Chain
    deactivate Node
    Client -->> Provider : Send Reference To Payment Voucher
    deactivate Client
    Provider ->> Node : Redeem Voucher On Payment Channel
    activate Node
    Node -->> Provider : Message For Voucher Redeemed On Chain
    deactivate Node
  end
  deactivate Provider
